#ifndef LOGILCD_H
#define LOGILCD_H

#include "qt_windows.h"

#define LOGI_LCD_TYPE_MONO    (0x00000001)
#define LOGI_LCD_TYPE_COLOR   (0x00000002)

#define LOGI_LCD_MONO_BUTTON_0 (0x00000001)
#define LOGI_LCD_MONO_BUTTON_1 (0x00000002)
#define LOGI_LCD_MONO_BUTTON_2 (0x00000004)
#define LOGI_LCD_MONO_BUTTON_3 (0x00000008)

#define LOGI_LCD_COLOR_BUTTON_LEFT   (0x00000100)
#define LOGI_LCD_COLOR_BUTTON_RIGHT  (0x00000200)
#define LOGI_LCD_COLOR_BUTTON_OK     (0x00000400)
#define LOGI_LCD_COLOR_BUTTON_CANCEL (0x00000800)
#define LOGI_LCD_COLOR_BUTTON_UP     (0x00001000)
#define LOGI_LCD_COLOR_BUTTON_DOWN   (0x00002000)
#define LOGI_LCD_COLOR_BUTTON_MENU   (0x00004000)

const int LOGI_LCD_MONO_WIDTH = 160;
const int LOGI_LCD_MONO_HEIGHT = 43;

const int LOGI_LCD_COLOR_WIDTH = 320;
const int LOGI_LCD_COLOR_HEIGHT = 240;

typedef bool (* LPFNDLLINIT)(wchar_t*, int );
typedef bool (* LPFNDLLISCONNECTED)(int);
typedef bool (* LPFNDLLISBUTTONPRESSED)(int);
typedef void (* LPFNDLLUPDATE)();
typedef void (* LPFNDLLSHUTDOWN)();
typedef bool (* LPFNDLLMONOSETBACKGROUND)(byte*);
typedef bool (* LPFNDLLMONOSETTEXT)(int, wchar_t*);
typedef bool (* LPFNDLLCCOLORSETBACKGROUND)(byte*);
typedef bool (* LPFNDLLCOLORSETTITLE)(wchar_t*, int, int, int);
typedef bool (* LPFNDLLCOLORSETTEXT)(int, wchar_t*, int, int, int);

#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QTimer>

class LogiLcd : public QObject
{
	Q_OBJECT

public:
	LogiLcd(QString title);
	~LogiLcd();
	bool isInit;
	bool repeate;

	void init();
	void setInterval(int msec);
	void SetMonoText(QString line1, QString line2, QString line3, QString line4);
	void SetMonoText(int line, QString text);
	void SetMonoAutoText(QString text, QFont font, Qt::GlobalColor color=Qt::white, int flags=Qt::TextWordWrap);
	void SetMonoAutoText(QString text, QString font="Times",  int size=6, bool white=true, int flags=Qt::TextWordWrap);

	void SetColorTitle(QString text,int r=0,int g=0,int b=0);
	void SetColorText(int line, QString text,int r=0,int g=0,int b=0);

	bool ResetScreen();
	bool SetRandomBackground();
	bool SetMonoBackgroundFromFile(QString fileName, Qt::AspectRatioMode aspectMode = Qt::KeepAspectRatio, Qt::AlignmentFlag alignment = Qt::AlignLeft);
	bool SetMonoBackgroundFromByteArray(QByteArray blob, Qt::AspectRatioMode aspectMode = Qt::KeepAspectRatio, Qt::AlignmentFlag alignment = Qt::AlignLeft);
	bool SetMonoBackgroundFromImage(QImage img, Qt::AspectRatioMode aspectMode = Qt::KeepAspectRatio, Qt::AlignmentFlag alignment = Qt::AlignLeft);
	bool SetColorBackgroundFromFile(QString fileName);

signals :
	void buttonPressed(int button);

private:
	QString title;

	LPFNDLLINIT LogiLcdInit;
	LPFNDLLISCONNECTED LogiLcdIsConnected ;
	LPFNDLLISBUTTONPRESSED LogiLcdIsButtonPressed;
	LPFNDLLUPDATE LogiLcdUpdate;
	LPFNDLLSHUTDOWN LogiLcdShutdown;
	LPFNDLLMONOSETBACKGROUND LogiLcdMonoSetBackground;
	LPFNDLLMONOSETTEXT LogiLcdMonoSetText;
	LPFNDLLCCOLORSETBACKGROUND LogiLcdColorSetBackground;
	LPFNDLLCOLORSETTITLE LogiLcdColorSetTitle;
	LPFNDLLCOLORSETTEXT LogiLcdColorSetText;

	QTimer *timer;
	int lastPressed;

	private slots:
		void timeout();


};

#endif // LOGILCD_H
